package Hot100.Medium;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LC128_LongestConsecutive {
    public static void main(String[] args) {

    }

    public int longestConsecutive(int[] nums){
        // 转化成哈希Set，快速查找以及去重
        Set<Integer> set = new HashSet<>();
        for(int num : nums){
            set.add(num);
        }
        int ans = 0;
        for(int x : set){
            if(set.contains(x - 1)){
                continue;
            }
            int y = x + 1;
            while (set.contains(y)){
                y++;
            }
            ans = Math.max(ans, y - x);
        }
        return ans;
    }
}
